package com.hm.syslog.config;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.UUID;

@Component
@Aspect
public class TraceAspect {

    @Value(value = "${spring.application.name}")
    private String serverName;

    @Value(value = "${spring.config.activate.on-profile}")
    private String env;
    
    @Pointcut("execution(public * com.hm.syslog.controller..*.*(..)) ")
    public void putTraceId() {
    }

    @Before("putTraceId()")
    public void before(JoinPoint point){
        MDC.put("TRACE_ID", UUID.randomUUID().toString());
        MDC.put("SERVER_NAME", serverName);
        MDC.put("PROFILE_ACTIVE", env);
    }

}